<?php
// +----------------------------------------------------------------------
// | 项目－后台扩展核心类，些类中有登录验证、权限验证、菜单读取……
// +----------------------------------------------------------------------
// | Copyright (c) 2015
// +----------------------------------------------------------------------
// | Author: baiping 125618036@qq.com http://www.webipcode.com
// +----------------------------------------------------------------------
// | 2015-6-25下午6:24:01
// +----------------------------------------------------------------------
defined('BASEPATH') OR exit('No direct script access allowed');
class MY_Controller extends  CI_Controller{
	
	private $error = '';
	
	public function __construct(){
		parent::__construct();
		error_reporting(E_ALL&~E_NOTICE);//去除Notice错误提示
		$this->load->helper('common');//加载公共函数库
		$this->load->vars('meta_title', '');
		//获取网站配置缓存
		$website = $this->getWebsitCache();
		$this->load->vars('webinfo', $website);
		//获取导航子栏目
		$this->getChildClass(157, 'trademark_menu');
		//获取专利产品列表
		$this->getChildClass(173, 'patent_child');
		//获取公司简介二级栏目
		$this->getChildClass(178, 'page_child');
		
		
	}
	
	/**
	 * 获取网站配置缓存
	 */
	public function getWebsitCache(){
		$this->load->driver('cache',array('adapter' => 'apc', 'backup' => 'file'));//载入缓存,以文件形式存储
		$website = $this->cache->get('config_data') ;
		return $website;
	}
	/**
	 * 弹出框口提示页
	 * @param string $status 状态（success/error）
	 * @param string $msg 提示信息
	 * @param string $tourl 跳转地址
	 */
	public function show_message($status='success', $msg='操作成功', $tourl=''){
		$tourl = empty( $tourl ) ? selfurl() : $tourl;
		$class_name = $status == 'success' ? 'alert-success' : 'alert-danger';
		$msg_arr = array(
				'class_name'=>$class_name,
				'msg_title' => $msg,
				'tourl'=> $tourl
		);
		$this->load->view('showmsg/show_message', $msg_arr);
	}
	
	/**
	 * 获取导航二级栏目
	 */
	public function getChildClass($bigclass, $list){
		if ( empty( $bigclass ) ){
			return false;
		}
		$this->load->model('Catgory_model','catgory_m');
		$child_list = $this->catgory_m->getData(0, array('pid'=>$bigclass,'hide'=>0));
		if ( !empty( $child_list ) ){
			$this->load->vars($list, $child_list);
		}
	}
	
	/**
	 * 获取专利列表
	 */
	protected function getPatentList(){
		$this->load->model('Patent_model', 'patent');
		$patent_list = $this->patent->getDataObj(array('state'=>0));
		if ( !empty( $patent_list ) ){
			$this->load->vars('patent_list', $patent_list);//专利列表
		}
	}
	
	/**
	 * 获取首页推荐商标
	 */
	protected function getTrademark($where,$limit=''){
		$this->load->model('Trademark_attr_model', 'trademark');//载入商标模型
		$field = "id, title, service_price,cat_id,server_intro";
		$trademark_list = $this->trademark->getData($where, $field, $limit, 0 );
		return $trademark_list;
	}
	
	/**
	 * 获取首页推荐专利
	 * @param unknown_type $limit
	 * @author Baip
	 */
	protected function getPatent($where, $limit = ''){
		$this->load->model('Patent_model', 'patent');//载入专利模型
		$field = "id, title, service_price, office_price, server_instro,thumb_id,thumb_path,cate_id";
		$patent_list = $this->patent->getDataObj( $where, $field, $limit, 0 );
		return $patent_list;
	}
	
	/**
	 * 获取专利产品详情
	 * @param unknown_type $where
	 * @param unknown_type $field
	 * @author Baip
	 */
	protected function getPatentInfo($where, $field="id, title, service_price, office_price"){
		$this->load->model('Patent_model', 'patent');//载入专利模型
		$patent_list = $this->patent->getFind( $where, $field );
		return $patent_list;
	}
	/**
	 * 错误信息
	 */
	public function error(){
		return $this->error;
	}
	
	
}